/*
 * @Date: 2023-03-18 09:19:10
 * @LastEditors: Zireael 1193875164@qq.com
 * @LastEditTime: 2023-03-23 15:31:57
 * @FilePath: \A19\backend\src\api\talks\ApiGetTalks.ts
 */
import { ApiCall } from "tsrpc";
import { ReqGetTalks, ResGetTalks } from "../../shared/protocols/talks/PtlGetTalks";
import { Global } from '../../Global/index';

export default async function (call: ApiCall<ReqGetTalks, ResGetTalks>) {
    // TODO
    const user = call.currentUser
    const { type,course } = call.req

    if(type === 'personal'){
        const ret = await Global.collection('talks').find({
            'user._id':user._id
        }).toArray()

        call.succ({
            talks:ret
        })
    }
    else{
        const ret = await Global.collection('talks').find(
        {
            course
        },
        {
            sort:[['time',-1]]
        }
        ).toArray()

        call.succ({
            talks:ret
        })
    }
}